<script>
//app.js
const Mta = require('./assets/js/mta_analysis.js');

const Api = require('./api/index.js'); // const Config = require('config/index.js')

const Util = require('./utils/sys-util.js');

const Share = require('./utils/sys-share.js'); 

// const MapSdk = require('utils/libs/wx-qqmap-jssdk.js')
// const Map = new MapSdk({
//   key: Config.qqmapKey
// })

export default {
    data() {
        return {};
    },
    onShow(options) {
        const self = this;
		console.log(options);
        if (options.scene) {
            //通过海报进入
            let sceneData = decodeURIComponent(options.scene);
            if (sceneData.indexOf('_') > 0) {
				console.log(sceneData);
                let newData = sceneData.split('_');
                let parentId = newData[1];
                self.globalData.top_code = parentId;
                uni.setStorageSync('top_code', parentId);
            }
        }
        if (options.query) {
            //通过分享进入
            if (options.query.code) {
                self.globalData.top_code = options.query.code;
                uni.setStorageSync('top_code', options.query.code);
            }
			if (options.query.scene) {
				 //通过海报进入
				let sceneData = decodeURIComponent(options.query.scene);
				if (sceneData.indexOf('_') > 0) {
				    let newData = sceneData.split('_');
				    let parentId = newData[1];
				    self.globalData.top_code = parentId;
				    uni.setStorageSync('top_code', parentId);
				}
			}
        }

        if (options.code) {
            //通过分享进入
            self.globalData.top_code = options.code;
            uni.setStorageSync('top_code', options.code);
        } 
		//回去存储的渠道信息
        if (self.globalData.top_code == '') {
            let promoteId = uni.getStorageSync('top_code');
            if (promoteId != undefined) {
                self.globalData.top_code = promoteId;
            }
        }

        uni.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline']
        }); // console.log(self.globalData);
    },
    onLaunch(options) {
        const self = this; //移动分析接入
		// 系统信息、iphoneX检测
        let menuButtonObject = uni.getMenuButtonBoundingClientRect();
        uni.getSystemInfo({
            success: (res) => {
                // console.log(menuButtonObject.height + (menuButtonObject.top - res.statusBarHeight)*2)
                // console.log(menuButtonObject.bottom + menuButtonObject.top - (res.statusBarHeight * 2))
                // self.globalData.navbarHeight = res.safeArea.bottom-res.safeArea.height+res.statusBarHeight;
                //获取标题栏高度
                self.globalData.navbarHeight = menuButtonObject.bottom + menuButtonObject.top - res.statusBarHeight * 2; //获取状态栏高度
                self.globalData.height = res.statusBarHeight;
                self.globalData.stickyTop = self.globalData.navbarHeight + self.globalData.height + 'px';
                let barHeight = res.screenHeight - res.safeArea.bottom;
                if (res.model.search('iPhone X') != -1 || barHeight >= 34) {
                    self.globalData.isIphoneX = true;
                }

                if (res.model.search('SM-G9550') != -1) {
                    // console.log("isGalaxy")
                    self.globalData.isGalaxy = true;
                }
            }
        });
        let appData = uni.getAccountInfoSync();
        this.globalData.appid = appData.appID; //系统更新检测
        Util.checkUpdate(); 				   //this.getLoginInfo();
    },
    /**
     * 全局变量
     */
    globalData: {
        title: '海之礼商城',
        appid: '',
        isGalaxy: false,
        isIphoneX: false,
		catIndex:2,//购物车下标
        //是否IphoneX
        stickyTop: '60px',

        //单位px
        navbarHeight: '86px',

        //标题栏高度
        access_token: null,

        //用户toekn
        business: 4,

        //商家认证  审核状态，0审核中，1已通过，2未通过 4未提交
        userInfo: {
            member_level: 0
        },

        //用户信息
        height: 0,

        //状态栏高度
        addressInfo: {
            nation: '',
            //国
            province: '',
            //省
            city: '',
            //市
            district: '',
            //区
            street: '',
            //街道
            street_number: '' //门牌
        },
		//上级推广进入的推广码
        top_code: '',

        //上级推广码
        service: '',

        //电话
        //用自己的推广码
        popularize_code: '',

        //获取登录信息
        getLoginInfo() {
            uni.login({
                success(res) {
                    var data = {
                        code: res.code,
                        type: 'one'
                    };
                    Api.getSessionKey(data).then((res) => {
                        if (res.code == 1) {
                            var data = res.data;
                            if (data.session_key == '') {
                                uni.setStorageSync('access_token', res.data.token);
                            }
                        }
                    });
                }
            });
        },

        /**
         * 清空token
         */
        _clearToken() {
            uni.removeStorageSync('userInfo');
            uni.removeStorageSync('access_token');
            this.access_token = null;
            this.userInfo = {};
        }
    }
};
</script>
<style>
	@import '/wxcomponents/vant/dist/common/index.css';
	@import './app.css';
</style>
<style lang="scss">
	@import "uview-ui/index.scss";
</style>

